import React from 'react'
import ViewList from './ViewList'
import Banner from './Banner'
import HeaderNav from './HeaderNav'
import request from '../api/axios'

class Main extends React.Component{

    constructor(props){
      
        super(props);
        this.state = {
            data:[
            ],
            datashow:[],
            flg:false
        };
        this.filerhandle = this.filerhandle.bind(this);
    }
    componentDidMount(){
        request.getData('data.json').then(res=>{
            console.log('getdatas',res);
            this.setState({data:res.data.data});
            this.setState({datashow:this.state.data})
        })
    }
// 过滤
    filerhandle(type){
        let temp =[];
         temp = this.state.data.filter((item)=>{
            if(item.type === type)
                return{...item};
            if(type === '4')
                return{...item}
        })
        // console.log(temp)
        this.setState({datashow:temp})
        // console.log(this.state.datashow);
        // console.log('*********')
    }

    render(){
        return(
            <div>
                <HeaderNav filerhandle={this.filerhandle}/>
                <Banner />
                <ViewList data={this.state.datashow} flg={!this.state.flg}/>
            </div>
        )
    }
}
export default Main